package Week1.J0418;

// 思路：写出斐波那契递归，判断n在两个Fib数之间，求距离两个数的最小值

import java.util.Scanner;

public class FibSeq {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(toBeFib(n));
    }

    private static int toBeFib(int n) {
        int ret = 0;
        for (int i = 1; i < n; i++) {
            if (Fib(i) < n && Fib(i+1) > n) {
                ret =  Math.min(n-Fib(i),Fib(i+1)-n);
                break;
            }
        }
        return ret;
    }

    private static int Fib(int n) {
        if (n == 1 || n == 2) {
            return 1;
        }
        return Fib(n-2) + Fib(n-1);
    }
}
